home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Leser 15
/
Amiga Plus Leser CD 15.iso
/
Tools
/
Development
/
PluginSRC_EvenMore
/
Eml2Text.e
< prev
next >
Wrap
Text File
|
2002-03-12
|
11KB
|
492 lines
/*
WordWorth2Text
EvenMore FileIO plugin
Author: Chris Perver
Copyright (c) 2001
*/
OPT REG=5
LIBRARY 'eml2text.plugin',1,1,'Eml2Text 1.09' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
MODULE 'tools/ctype', '*epo', '*converthtml'
DEF mem2, count2 = 0
PROC em_isdatatype(bf:PTR TO CHAR, bl)
DEF working = TRUE, i = 0, c = 0,rc= FALSE
DEF str[20]:STRING
WHILE working
WHILE working ->(bf[i] <> "\n")
EXIT (bf[i] = "\n") OR (bf[i] = "\b")
INC i
IF (i>=bl) THEN working := FALSE
ENDWHILE
INC i
SELECT 256 OF bf[c]
CASE "M", "m"
StrCopy(str, bf + c, 15)
UpperStr(str)
IF InStr(str, 'MIME-VERSION: ') = 0
working := FALSE
rc := TRUE
ELSE
c := i
ENDIF
DEFAULT
c := i
ENDSELECT
ENDWHILE
ENDPROC rc
PROC em_parsedata(epo:PTR TO em_pluginobj)
DEF count = 0
DEF notdone = TRUE
DEF i, eol, j, eml[256]:STRING, bound[256]:STRING
DEF format = 0
DEF isprint = FALSE, isbound = FALSE
DEF htmlstart = 0, htmlend, notbegun = TRUE
DEF hex:PTR TO CHAR, eolchar:PTR TO CHAR, memadr:PTR TO CHAR, lenadr
DEF crlf = FALSE, loop, printable = FALSE
StrCopy(bound, '')
memadr := epo.buffer
lenadr := epo.length
mem2 := epo.nbuffer
i := count
WHILE ((memadr[i] <> "\n") AND (memadr[i] <> "\b")) DO INC i
IF memadr[i] = "\n"
-> IF memadr[i-1] = "\b"
-> eolchar := "\n"
-> ELSE
eolchar := "\n"
-> ENDIF
ELSE
IF memadr[i+1] = "\n"
crlf := TRUE
eolchar := "\n"
ELSE
eolchar := "\b"
ENDIF
ENDIF
WHILE notdone AND (count < lenadr)
eol := count
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
UpperStr(StrCopy(eml, memadr + count, eol - count))
IF InStr(eml, 'FROM:') = 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "4"
mem2[count2++] := "3"
mem2[count2++] := "m"
WHILE (count < eol) DO mem2[count2++] := memadr[count++]
count := eol
ELSEIF InStr(eml, 'TO:') = 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "4"
mem2[count2++] := "3"
mem2[count2++] := "m"
WHILE (count < eol) DO mem2[count2++] := memadr[count++]
count := eol
ELSEIF InStr(eml, 'DATE:') = 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "4"
mem2[count2++] := "3"
mem2[count2++] := "m"
WHILE (count < eol) DO mem2[count2++] := memadr[count++]
count := eol
ELSEIF InStr(eml, 'SUBJECT:') = 0
mem2[count2++] := "\e"
mem2[count2++] := "["
mem2[count2++] := "4"
mem2[count2++] := "3"
mem2[count2++] := "m"
WHILE (count < eol) DO mem2[count2++] := memadr[count++]
count := eol
ELSEIF InStr(eml, 'CONTENT-TRANSFER-ENCODING: ') = 0
IF isprint
IF InStr(eml, 'QUOTED-PRINTABLE') >= 0 THEN printable := TRUE
ENDIF
count := eol
ELSEIF InStr(eml, 'CONTENT-TYPE:') = 0
IF InStr(eml, 'TEXT/HTML') >= 0
IF format = 0
format := 2
ENDIF
j := count
WHILE memadr[j] <> ";" DO INC j
INC j
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
IF format = 2
-> CHECK IF WE ARE TO REALIGN LF's
StrCopy(eml, memadr + eol, 50)
UpperStr(eml)
IF InStr(eml, 'QUOTED-PRINTABLE') >= 0 THEN printable := TRUE
ENDIF
-> count := eol
IF format = 2
isprint := TRUE
mem2[count2++] := "\n"
-> SKIP UNTIL WE HIT 2 LF's WHICH IS WHERE OUR MESSAGE STARTS
loop := TRUE
WHILE loop
WHILE memadr[eol] <> eolchar DO INC eol
IF crlf
IF memadr[eol+2] = eolchar
eol := eol + 2
loop := FALSE
ENDIF
ELSE
IF memadr[eol+1] = eolchar
INC eol
loop := FALSE
ENDIF
ENDIF
INC eol
ENDWHILE
-> INC eol
ELSE
isprint := FALSE
-> Skip until next boundary!
WHILE TRUE
-> SKIP LINE UNTIL WE GET FIRST BOUNDS
j := eol
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
StrCopy(eml, memadr + j, eol - j)
UpperStr(eml)
EXIT (InStr(eml, bound) >= 0)
ENDWHILE
-> count := eol
ENDIF
count := eol
ELSEIF InStr(eml, 'MULTIPART') >= 0
IF InStr(eml, '/ALTERNATIVE') >= 0 THEN format := 2
j := count
WHILE memadr[j] <> ";" DO INC j
INC j
StrCopy(eml, memadr + j, 50)
UpperStr(eml)
IF InStr(eml, 'BOUNDARY=') >= 0
-> GET START OF STRING
WHILE memadr[j] <> $22 DO INC j
INC j
-> GET END OF STRING
eol := j
WHILE memadr[eol] <> $22 DO INC eol
StrCopy(bound, memadr + j , eol-j -1)
UpperStr(bound)
isbound := TRUE
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
ELSEIF InStr(eml, 'CHARSET=') >= 0
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
ENDIF
count := eol
-> Skip until next boundary!
WHILE TRUE
-> SKIP LINE UNTIL WE GET FIRST BOUNDS
j := eol
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
StrCopy(eml, memadr + j, eol - j)
UpperStr(eml)
EXIT (InStr(eml, bound) >= 0)
ENDWHILE
count := eol
ELSEIF InStr(eml, 'TEXT/PLAIN') >= 0
IF format = 0 THEN format := 1
j := count
WHILE memadr[j] <> ";" DO INC j
INC j
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
IF format = 1
-> CHECK IF WE ARE TO REALIGN LF's
StrCopy(eml, memadr + eol, 50)
UpperStr(eml)
IF InStr(eml, 'QUOTED-PRINTABLE') >= 0 THEN printable := TRUE
ENDIF
IF format = 1
isprint := TRUE
mem2[count2++] := "\n"
-> SKIP UNTIL WE HIT 2 LF's WHICH IS WHERE OUR MESSAGE STARTS
loop := TRUE
WHILE loop
WHILE memadr[eol] <> eolchar DO INC eol
IF crlf
IF memadr[eol+2] = eolchar
eol := eol + 2
loop := FALSE
ENDIF
ELSE
IF memadr[eol+1] = eolchar
INC eol
loop := FALSE
ENDIF
ENDIF
INC eol
ENDWHILE
ELSE
-> Skip until next boundary!
WHILE TRUE
-> SKIP LINE UNTIL WE GET FIRST BOUNDS
j := eol
WHILE memadr[eol] <> eolchar DO INC eol
INC eol
StrCopy(eml, memadr + j, eol - j)
UpperStr(eml)
EXIT (InStr(eml, bound) >= 0)
ENDWHILE
isprint := FALSE
ENDIF
count := eol
ELSE
count := eol
ENDIF
ELSE
IF isprint
IF isbound
IF InStr(eml, bound) >= 0
count := eol
isprint := FALSE
ENDIF
ENDIF
WHILE count < eol
IF notbegun
htmlstart := count2
notbegun := FALSE
ENDIF
SELECT 256 OF memadr[count]
CASE "="
SELECT 256 OF memadr[count+1]
CASE " "
WHILE memadr[count] <> eolchar DO INC count
INC count
CASE "\b"
WHILE memadr[count] <> eolchar DO INC count
INC count
CASE "\n"
WHILE memadr[count] <> eolchar DO INC count
INC count
DEFAULT
IF (printable = FALSE) ->(memadr[count+1] = eolchar) OR (memadr[count + 2] = eolchar)
mem2[count2++] := memadr[count++]
ELSE
SELECT 256 OF memadr[count + 1]
CASE "0"; hex := $00
CASE "1"; hex := $10
CASE "2"; hex := $20
CASE "3"; hex := $30
CASE "4"; hex := $40
CASE "5"; hex := $50
CASE "6"; hex := $60
CASE "7"; hex := $70
CASE "8"; hex := $80
CASE "9"; hex := $90
CASE "A"; hex := $A0
CASE "B"; hex := $B0
CASE "C"; hex := $C0
CASE "D"; hex := $D0
CASE "E"; hex := $E0
CASE "F"; hex := $F0
ENDSELECT
SELECT 256 OF memadr[count + 2]
CASE "0"; hex := hex + $00
CASE "1"; hex := hex + $01
CASE "2"; hex := hex + $02
CASE "3"; hex := hex + $03
CASE "4"; hex := hex + $04
CASE "5"; hex := hex + $05
CASE "6"; hex := hex + $06
CASE "7"; hex := hex + $07
CASE "8"; hex := hex + $08
CASE "9"; hex := hex + $09
CASE "A"; hex := hex + $0A
CASE "B"; hex := hex + $0B
CASE "C"; hex := hex + $0C
CASE "D"; hex := hex + $0D
CASE "E"; hex := hex + $0E
CASE "F"; hex := hex + $0F
ENDSELECT
mem2[count2++] := hex
count := count + 3
ENDIF
ENDSELECT
-> ENDIF
DEFAULT
mem2[count2++] := memadr[count++]
ENDSELECT
ENDWHILE
count := eol
ELSE
count := eol
ENDIF
ENDIF
-> INC count
ENDWHILE
mem2[count2] := "\n"
htmlend := count2
IF format = 2
mem2, count2 := convhtml(mem2, htmlstart, htmlend)
ENDIF
-> IF memadr
-> Dispose(memadr); memadr := NIL
-> ENDIF
ENDPROC mem2, count2
-><
-> *** STANDARD PROCS FOR PLUGINS
PROC em_main(epo:PTR TO em_pluginobj)
DEF len2
mem2, len2 := em_parsedata(epo)
epo.nlength := len2
RETURN TRUE
ENDPROC
PROC em_begin(epo:PTR TO em_pluginobj)
IF em_isdatatype(epo.buffer, epo.length)
RETURN "MEM", (epo.length * 2)
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC em_end() IS EMPTY
PROC em_info() IS 'Eml2Text 1.09'
PROC em_format() IS 'Mime'
PROC em_pluginid() IS "FILE"
PROC main() IS EMPTY